﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<!--easyui-->
<link type="text/css" href="../../Scripts/easyui-1.8.20/css/smoothness/jquery-ui-1.8.20.custom.css"
    rel="stylesheet" />

<script type="text/javascript" src="../../Scripts/easyui-1.8.20/js/jquery-1.7.2.min.js"></script>

<script type="text/javascript" src="../../Scripts/easyui-1.8.20/js/jquery-ui-1.8.20.custom.min.js"></script>

<style type="text/css">
    .ui-autocomplete
    {
        max-height: 150px;
        overflow-y: auto; /* prevent horizontal scrollbar */
        overflow-x: hidden; /* add padding to account for vertical scrollbar */
        padding-right: 20px;
    }
</style>

<script type="text/javascript">
    
    $( function() {
        $("#txt_str").autocomplete({
            source: function(request, response) {
                $.ajax({
                    url: "/Home/SearchUserFormAll",  //要查询的Action
                    type: "POST",  //Post提交
                    dataType: "json", //json格式数据，默认是text
                    data: { keyword: request.term }, //参数，不知道为什么？请指点
                    
                    //data: {keyword:$("#keyword").val()},同样可以
                    success: function(data) {
                        response($.map(data, function(item) {
                            return { label: item.text, value: item.value }; //将返回的jsonresult的属性赋值给autocomplete item
                        }));
                    }
                });
            },
            select: function(event, ui) {
                var t=ui.item.label;//'马军 事业部 员工'
                var arr= t.split(' ');
                $('#txt_str').val(arr[0]);  //选中item的文本
                $('#txt_strid').val(ui.item.value); //选中item的值
                return false;
            },
            minLength:'0',
        })
       
        tableSelectOrder("#mywfdelegmrg .table_style");
    })
    
    function doAddWfDeleg() {
        var deleg_wtr = $("#deleg_wtr").val();
        var deleg_str = $("#txt_strid").val();
        if (deleg_wtr == "" || deleg_str == "") {
            alert("请选择人员");
            return;
        }
        if(deleg_wtr==deleg_str){
            alert("员工不得委托给本人");
            return;
        }

        $.ajax({
            url: "/WorkFlow/DoAddWfDeleg",
            type: "POST",
            data: { deleg_wtr: deleg_wtr, deleg_str: deleg_str },
            success: proRes,
        })
    }

    function doCancelWfDeleg() {
        var deleg_wtr = $("#deleg_wtr").val();
        $.ajax({
            url: "/WorkFlow/DoCancelWfDeleg",
            type: "POST",
            data:{deleg_wtr:deleg_wtr},
            success: proRes,
        })
    }
    function proRes(restag) {
        if(!restag.res){
            alert(restag.msg);
        }
        else
        {
            alert("操作成功");
            $('#menu_wfdeleg').trigger('click');
        }
    }
    
</script>

<div id="mywfdelegmrg" style="padding-top: 35px;">
    <div style="margin: 5px 20px 5px 300px;">
        委托给：
        <%=Html.TextBox("txt_str")%>
        <input class="btn_style" type="button" onclick="doAddWfDeleg()" value="发起委托" />
        <input class="btn_style" type="button" onclick="doCancelWfDeleg()" value="取消委托" />
        <%=Html.Hidden("txt_strid")%><%--//智能查询选中的值--%>
        <%=Html.Hidden("deleg_wtr",ViewData["deleg_wtr"])%>
    </div>
    <div>
        <table border="0" width="100%" class="table_style" cellpadding="0" cellspacing="0">
            <thead>
                <tr>
                    <th>
                        受托人
                    </th>
                    <th>
                        申请时间
                    </th>
                    <th>
                        结束时间
                    </th>
                    <th>
                        状态
                    </th>
                </tr>
            </thead>
            <tbody>
                <%
                    System.Data.DataTable dt_deleg = ViewData["dt_deleg"] as System.Data.DataTable;
                    if (dt_deleg != null && dt_deleg.Rows.Count != 0)
                    {
                        for (int i = 0; i < dt_deleg.Rows.Count; i++)
                        {
                %>
                <tr>
                    <td>
                        <%=dt_deleg.Rows[i]["受托人"]%>
                    </td>
                    <td>
                        <%=DateTime.Parse(dt_deleg.Rows[i]["开始时间"].ToString()).ToString("yyyy-MM-dd HH:mm")%>
                    </td>
                    <td>
                        <%=dt_deleg.Rows[i]["结束时间"].ToString() == "" ? "" : DateTime.Parse(dt_deleg.Rows[i]["开始时间"].ToString()).ToString("yyyy-MM-dd HH:mm")%>
                    </td>
                    <td>
                        <%=dt_deleg.Rows[i]["状态"].ToString() == "1" ? "有效" : "无效"%>
                    </td>
                </tr>
                <%
                    }
                    }
                    else
                    { %>
                <tr>
                    <td colspan="0" style="text-align: center;">
                        当前无数据！
                    </td>
                </tr>
                <%} %>
            </tbody>
        </table>
    </div>
</div>
